//
//  CLAlertView.m
//  test
//
//  Created by Phyllis Hu on 15-5-12.
//  Copyright (c) 2015年 Phyllis Hu. All rights reserved.
//

#import "CLAlertView.h"
#import "MBProgressHUD+MJ.h"

@interface CLAlertView()<UIAlertViewDelegate>
@property (nonatomic, copy) alertViewBlock okBlock;
@property (nonatomic, copy) alertViewBlock cancelBlock;
@property (nonatomic, copy) alertViewBlock twoBlock;
@end

@implementation CLAlertView

- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitles:(NSString *)otherButtonTitles cancelBlock:(alertViewBlock)cancel okBlock:(alertViewBlock)ok
{
    if (self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil]) {
        self.okBlock = ok;
        self.cancelBlock = cancel;
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle oneButtonTitles:(NSString *)oneButtonTitles twoButtonTitles:(NSString *)twoButtonTitles cancelBlock:(alertViewBlock)cancel oneBlock:(alertViewBlock)oneBlock twoBlock:(alertViewBlock)twoBlock
{

    if (self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:oneButtonTitles,twoButtonTitles, nil]) {
        self.okBlock = oneBlock;
        self.twoBlock = twoBlock;
        self.cancelBlock = cancel;
    }

    return self;
}


+ (void)showMsg:(NSString *)msg
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil, nil];
    [alert show];
}

+ (void)hideHudAndShowMsg:(NSString *)msg
{
    [MBProgressHUD hideHUD];
    [self showMsg:msg];
}

+ (void)showTitle:(NSString *)title message:(NSString *)msg
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil, nil];
    [alert show];
}

#pragma mark - alertView代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        if (self.cancelBlock) {
            self.cancelBlock();
        }
    } else if (buttonIndex == 1) {
        if (self.okBlock) {
            self.okBlock();
        }
    }else if (buttonIndex == 2){
        if (self.twoBlock) {
            self.twoBlock();
        }
    }
}

@end
